package cn.wolfcode.trip.base.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Getter @Setter @ToString
@AllArgsConstructor
@NoArgsConstructor
public class Message {
    public static final int TYPE_NORMAL = 1;            //信息类型:会话
    public static final int TYPE_CROWD = 2;             //信息类型:群会话
    public static final int TYPE_ADD_FRIEND = 3;        //信息类型:加好友
    public static final int TYPE_CROWD_INVITE = 4;      //信息类型:群邀请

    public static final int STATE_UNREAD = 1;           //信息状态:未读
    public static final int STATE_MARK_READ = 2;        //信息状态:已读
    public static final int STATE_REJECT = 0;           //信息状态:拒绝


    private Long id;            //信息的id

    private User user;          //信息发送人

    private User target;        //信息接收人

    private Integer type = TYPE_NORMAL;       //信息的类型

    private Integer state = STATE_UNREAD;      //信息的状态

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date creatdate;     //信息的创建时间

    private MessageContent content;     //信息的内容

    public String getTypeDisplay(){
        switch (type){
            case TYPE_NORMAL:return "会话";
            case TYPE_CROWD:return "群会话";
            case TYPE_ADD_FRIEND:return "加好友";
            case TYPE_CROWD_INVITE:return "群邀请";
        }
        return "";
    }

    public String getStateDisplay(){
        if(state ==STATE_UNREAD){
            return "未读";
        }else if(state == STATE_MARK_READ){
            return "已读";
        }else if(state == STATE_REJECT){
            return "拒绝";
        }
        return "";
    }
}